package com.maomao.maomaochong_i.fenLeiPackage;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.SearchView;

import com.maomao.maomaochong_i.R;

/**
 * Created by maomao on 2017/5/17.
 */

public class FenLeiPageSearch extends AppCompatActivity {
    private String[] name = { "IPHONE7PLUS", "IPHONE7", "IPHONE6SPLUS",
            "IPHONE6S", "IPHONE6PLUS", "IPHONE6", "IPHONE5S", "IPHONE5C", "笔记本电脑", "平板电脑", "配件"};
    private SearchView searchView;
    private ListView listView;
    private ImageButton imageButton;

    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fenlei_search);
        /////////////////////////////
        searchView = (SearchView) findViewById(R.id.searchView);
        imageButton = (ImageButton) findViewById(R.id.imageButton);


        listView = (ListView) findViewById(R.id.searchList);
        listView.setAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_expandable_list_item_1,name));
        listView.setTextFilterEnabled(true);

        //设置搜索文本监听
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            // 当点击搜索按钮时触发该方法
            public boolean onQueryTextSubmit(String query) {
                return false;
            }

            // 当搜索内容改变时触发该方法
            public boolean onQueryTextChange(String newText) {

                if (!TextUtils.isEmpty(newText)){
                    listView.setFilterText(newText);
                }else{
                    listView.clearTextFilter();
                }
                return false;
            }
        });

        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}


